<?php
class mmg_user extends CI_Model{
	var $mgt_user = "mgt_user";

	function __construct()
	{
		parent::__construct();
	}
	
	function setData($id_user,$nama_user,$email_user,$chat_user,$pass_user,$enable_user)
	{
		$this->id_user= $id_user;
		$this->nama_user= $nama_user;
		$this->email_user= $email_user;
		$this->chat_user= $chat_user;
		$this->pass_user= $pass_user;
		$this->enable_user= $enable_user;
	}
	
	function getList(){
		$query = $this->db->get($this->mgt_user);
		if($query->num_rows() > 0){
			foreach($query->result_array() as $row){
				$result[] = $row;
			}
			return $result;
		} else {
			return false;
		}	
	}	
	
	function create()
	{		
		$arrayData = array(
			'id_user'=>$this->id_user,
			'nama_user'=>$this->nama_user,
			'email_user'=>$this->email_user,
			'chat_user'=>$this->chat_user,
			'pass_user'=>$this->pass_user,
			'enable_user'=>$this->enable_user
		);
		return $this->db->insert($this->mgt_user, $arrayData);
	}
	
	function update($id_user)
	{
		$arrayData = array(
			'nama_user'=>$this->nama_user,
			'email_user'=>$this->email_user,
			'chat_user'=>$this->chat_user,
			'pass_user'=>$this->pass_user,
			'enable_user'=>$this->enable_user
		);
		$this->db->where('id_user', $id_user);
		return $this->db->update($this->mgt_user, $arrayData);
	}
        
	function remove($id_user)
	{
		$this->db->where('id_user', $id_user);
		return $this->db->delete($this->mgt_user);
	}	
	
	function detail($id_user)
	{
		$this->db->where('id_user', $id_user);
		$query = $this->db->get($this->mgt_user);	
		return $query->result_array();
	}
	
	function checkuser($username,$password){
		$this->db->where('nama_user', $username);
		$this->db->where('pass_user', $password);
		$this->db->where('enable_user', "1");
		$query = $this->db->get($this->mgt_user);
		   
		if($query->num_rows == 1){
		   return true;
		}
	}
	
}
?>